package com.example.mysimpleexample.adapter;

import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.example.mysimpleexample.R;
import com.example.mysimpleexample.entity.News;
import com.xuexiang.xui.widget.imageview.ImageLoader;
import com.xuexiang.xutil.common.CollectionUtils;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class NewsAdapter extends BaseQuickAdapter<News, BaseViewHolder> {
    public NewsAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, News news) {
        holder.setText(R.id.tv_title,news.getTitle());
        holder.setText(R.id.tv_source,news.getSource());
        holder.setText(R.id.tv_posttime,news.getPostTime());
        ImageView ivImg = holder.getView(R.id.iv_img);
        if (CollectionUtils.isNotEmpty(news.getImgList())) {
            ImageLoader.get().loadImage(ivImg,news.getImgList().get(0));
        }else{
            holder.setGone(R.id.iv_img,true);
        }
    }
}
